﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using agvcontroller.Common;
using agvcontroller.Common.DataBase;
using agvcontroller.Log;

namespace agvcontroller.Common
{
    public class CLockZone
    {
        public int ID
        {
            get;
            set;
        }
    }

    public class CLockZoneDic : Dictionary<int, CLockZone>
    {
        private static CLockZoneDic uniqueInstance;
        CAGVCDB AGVCDB;
        Logger Log;

        public static CLockZoneDic getInstance()
        {
            if (uniqueInstance == null)
            {
                uniqueInstance = new CLockZoneDic();
            }
            return uniqueInstance;
        }

        public CLockZoneDic()
        {
            AGVCDB = CAGVCDB.getInstance();

            Log = new Logger("LockZoneDic");

            GetDataFromDB();
        }

        int GetDataFromDB()
        {
            DataTable table = AGVCDB.AGVCDataSet.Tables["NodeList"];

            CLockZone lockzone;

            try
            {
                foreach (DataRow row in table.Rows)
                {
                    lockzone = new CLockZone();
                    lockzone.ID = Convert.ToInt32(row["ID"]);

                    this.Add(lockzone.ID, lockzone);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(string.Format("{0},{1}", ex.Message, ex.StackTrace));
                return CReturnCode.ERR_DATA_ACQUIRING_FAIL;

            }

            return CReturnCode.SUCCESS;
        }

        int SetDataToDB()
        {
            return CReturnCode.SUCCESS;
        }
    }
}
